﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="~/layui/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
    <link href="~/layui/css/public.css" rel="stylesheet" />
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>


    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">耗材名称</label>
            <div class="layui-input-block">
                <input type="text" name="ConsumableName" lay-verify="required" lay-reqtext="耗材信息名称不能为空" placeholder="请输入耗材信息名称" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">计量单位</label>
            <div class="layui-input-block">
                <input type="text" name="Unit" lay-verify="required" lay-reqtext="单位不能为空" placeholder="请输入单位" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">价格</label>
            <div class="layui-input-block">
                <input type="number" name="Money" lay-verify="required" lay-reqtext="价格不能为空" placeholder="请输入价格" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">耗材规格</label>
            <div class="layui-input-block">
                <input type="text" name="Specification" lay-verify="required" lay-reqtext="耗材规格不能为空" placeholder="请输入耗材规格" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">警告库存</label>
            <div class="layui-input-block">
                <input type="email" name="WarningNum" placeholder="请输入警告库存" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
                <select id="service" name="CategoryId" lay-verify="required" class="select">
                    <option value="0">请选择耗材分类</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label layui-required">描述：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入耗材信息描述" oninput="wordLeg(this);" maxlength="100" onpropertychange="if(value.length>100) value=value.substr(0,100)" name="Description" class="layui-textarea"></textarea>
                <div class="word"><span class="text_count">0</span>&nbsp;/&nbsp;<span class="num_count" id="numCount">100</span></div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>


    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui/lib/layui-v2.6.3/layui.js"></script>
    <script src="~/layui/js/lay-module/tableSelect/tableSelect.js"></script>
    <script>

        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            //主管下拉框
            layui.use('form', function () {
                var $ = layui.jquery
                var form = layui.form
                $.ajax({
                    url: '/ConsumableInfo/getConsumableInfoSelect',
                    dataType: 'json',
                    type: 'get',
                    success: function (res) {
                        console.log(res);
                        if (res.data !== null) {
                            $("#service").empty();
                            $("#service").append(new Option("请选择耗材信息", "0"));
                            $.each(res.data, function (index, value) {
                                $('#service').append(new Option(value._categoryName, value.id));// 下拉菜单里添加元素
                            });
                        } else {
                            $("#service").append(new Option("暂无数据", ""));
                        }
                        //重新渲染
                        form.render("select");
                    }
                });
            });

            //描述字数
            window.wordLeg = function (obj) {
                var currleg = $(obj).val().length;
                var length = $(obj).attr('maxlength');
                if (currleg > length) {
                    layer.msg('字数请在' + length + '字以内');
                } else {
                    $('.text_count').text(currleg);
                }
            }
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.ajax({
                    url: "/ConsumableInfo/AddConsumableInfo",
                    type: "put",
                    data: data.field,
                    success: function (res) {
                        if (res.data) {
                            layer.alert(res.msg, { icon: 1 }, function () {
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            })
                        } else {
                            layer.alert(res.msg)
                        }
                    }
                }),
                    // 关闭弹出层
                    layer.close(index);
            });

        });
    </script>
</body>
</html>
